// 登录信息管理仓库
import { request } from "../utils/Request.js";
export default ({
    namespaced:true,
    state: {
        isLogin:sessionStorage.getItem('isLogin') || false,
        token:sessionStorage.getItem('token') || null,
        userId:sessionStorage.getItem('userId') || '0000',
        userName:sessionStorage.getItem('userName') || '请登录',
    },
    mutations: {
        changeIsLogin(state,playload){
            let data={
                isLogin:true,
                token:playload.token,
                userId:playload.id,
                userName:playload.name
            }
            state.isLogin=data['isLogin']
            sessionStorage.setItem('isLogin',state.isLogin)
            state.token=data['token']
            sessionStorage.setItem('token',state.token)
            state.userId=data['userId']
            sessionStorage.setItem('userId',state.userId)
            state.userName=data['userName']
            sessionStorage.setItem('userName',state.userName)
        },
    },
    actions: {
        async changeIsLogin({ commit },playload){
            const resBack=await request('/login',playload)
            console.log(resBack.data.result);
            commit('changeIsLogin',{
                isLogin:true,
                token:resBack.data.result.token,
                userId:resBack.data.result.id,
                userName:resBack.data.result.name
            })
        }
    },
})